package com.nhc.activity_fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.astrob.naviframe.Start;
import com.astrob.nhcmap.R;
import com.astrob.util.SysUtils;
import com.nhc.database.dbmodel.Measure;
import com.nhc.database.manager.MeasureCenter;
import com.nhc.model.TripItem;
import com.nhc.view.TripItemViewLayout;

import zuo.biao.library.base.BaseActivity;

public class MeasureInfoActivity extends BaseActivity implements View.OnClickListener {
    private final String TAG = "MeasureInfoActivity";

    //启动方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    static final String INTENT_DATA_MID = "INTENT_DATA_MID";

    /**
     * 启动这个Activity的Intent
     *
     * @param context
     * @return
     */
    public static Intent createIntent(Context context, Long measureId) {
        return new Intent(context, MeasureInfoActivity.class)
                .putExtra(INTENT_DATA_MID, measureId);
    }
    //启动方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Measure _measure;

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.measureinfo_activity);

        intent = getIntent();
        Long measureId = intent.getLongExtra(INTENT_DATA_MID, 0);
        _measure = MeasureCenter.getInstance().getMeasureById(measureId);
        if (_measure == null) {
            return;
        }

        //功能归类分区方法，必须调用<<<<<<<<<<
        initView();
        initData();
        initEvent();
        //功能归类分区方法，必须调用>>>>>>>>>>

    }

    //UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    private TextView tv_name;
    private TripItemViewLayout tripiemview[] = new TripItemViewLayout[4];
    private int[] LL_CTRL = {R.id.msinfoview_0, R.id.msinfoview_1, R.id.msinfoview_2, R.id.msinfoview_3};

    @Override
    public void initView() {//必须调用
        tv_name = (TextView) findViewById(R.id.tv_name);
        for (int i = 0; i < LL_CTRL.length; i++) {
            tripiemview[i] = (TripItemViewLayout) findViewById(LL_CTRL[i]);
        }
    }

    //UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    //Data数据区(存在数据获取或处理代码，但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    @Override
    public void initData() {//必须调用

        String name = _measure.getName();
        if (_measure.getAreatype() == 1) {
            name = "[" + getString(R.string.dkmjcl) + "]\n" + name;
        } else if (_measure.getAreatype() == 2) {
            name = "[" + getString(R.string.pmcl) + "]\n" + name;
        }

        tv_name.setText(name);

        double area = 0;
        if (_measure.getType() == 0) {
            findViewById(R.id.ctrl_area).setVisibility(View.GONE);
        } else if (_measure.getType() == 1) {
            area = _measure.getArea();
            if (_measure.getAreatype() == 1) {
                area = _measure.getAreade();
            } else if (_measure.getAreatype() == 2) {
                double aa = Math.cos(_measure.getSlopeangle());
                if (aa != 0) {
                    area /= aa;
                }
                if (area < 0) {
                    area = -area;
                }
            }
        }

        String ARE[] = SysUtils.getInstance().getAreaStr(area);
        tripiemview[3].bindView(new TripItem(getString(R.string.mianji), ARE[0], ARE[1]));

        String LEN[] = SysUtils.getInstance().getDistanceStr((int) _measure.getLength());
        tripiemview[0].bindView(new TripItem(getString(R.string.changdu), LEN[0], LEN[1]));

        String PER[] = SysUtils.getInstance().getDistanceStr((int) _measure.getPerimeter());
        tripiemview[2].bindView(new TripItem(getString(R.string.zouchang), PER[0], PER[1]));

        int size = _measure.num;
        if (_measure.num < 1 && _measure.measurePtList != null) {
            size = _measure.measurePtList.size();
        }

        tripiemview[1].bindView(new TripItem(getString(R.string.dianshuliang), size + "", ""));
    }

    //Data数据区(存在数据获取或处理代码，但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    @Override
    public void initEvent() {//必须调用

    }
    //系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


    //类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


    @Override
    public void onClick(View v) {

    }

    //类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    //系统自带监听方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


}
